package com.glp.work.flow.service.impl;

import com.glp.fbs.api.dto.user.PersonInfoDto;
import com.glp.work.flow.mapper.WfUserSuperiorMapper;
import com.glp.work.flow.pojo.WfUserSuperior;
import com.glp.work.flow.service.WfUserSuperiorService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

/**
 * @author : 郭永伟
 * @date : 2020/10/21/11:16
 * @description : 用户对应的上下级
 */
@Service
public class WfUserSuperiorServiceImpl implements WfUserSuperiorService {
    @Resource
    private WfUserSuperiorMapper wfUserSuperiorMapper;

    @Override
    public void insertUserNo(WfUserSuperior wfUserSuperior) {
        Example example = new Example(WfUserSuperior.class);
        example.createCriteria().andEqualTo("userNo", wfUserSuperior.getUserNo());
        WfUserSuperior wfUserSuperior1 = wfUserSuperiorMapper.selectOneByExample(example);
        if (wfUserSuperior1 != null) {
            wfUserSuperiorMapper.updateByExampleSelective(wfUserSuperior, example);
        } else {
            wfUserSuperiorMapper.insertSelective(wfUserSuperior);
        }
    }


    @Override
    public void updateOnUserNo(String assignee, PersonInfoDto personInfo) {
        if (personInfo != null) {
            String parentUserNo = personInfo.getParentUserNo();
            WfUserSuperior wfUserSuperior = new WfUserSuperior();
            wfUserSuperior.setOnUserNo(assignee);
            wfUserSuperior.setOnSuperiorNo(parentUserNo);
            insertOnUserNo(wfUserSuperior);
        }
    }

    public void insertOnUserNo(WfUserSuperior wfUserSuperior) {
        Example example = new Example(WfUserSuperior.class);
        example.createCriteria().andEqualTo("onUserNo", wfUserSuperior.getOnUserNo());
        WfUserSuperior wfUserSuperior1 = wfUserSuperiorMapper.selectOneByExample(example);
        if (wfUserSuperior1 != null) {
            wfUserSuperiorMapper.updateByExampleSelective(wfUserSuperior, example);
        } else {
            wfUserSuperiorMapper.insertSelective(wfUserSuperior);
        }
    }


}
